<script setup>
import {h, ref} from "vue";
import axios from "axios";
import {ElNotification} from "element-plus";
const fullscreenLoading = ref(false)
const form=ref({
  old_pwd:'',
  new_pwd:'',
  re_pwd:''
})
const updatepwd=()=>{
axios.patch("/user/updatePwd",form.value).then(result=>{
if (result.data.code==0){
  fullscreenLoading.value = true
  setTimeout(() => {
    localStorage.clear();
    fullscreenLoading.value = false
  }, 2800)
  return   ElNotification({
    title: '消息',
    message: h('i', { style: 'color: teal' },"更新密码成功"),
  })
}

}).catch(err=>{
  return   ElNotification({
    title: '消息',
    message: h('i', { style: 'color: teal' },"更新失败"),
  })
})
}
const rules=ref({
  old_pwd:[{required:true,message:'请输入您的旧密码',trigger:'blur'}],
  new_pwd:[{required:true,message:'请输入新密码',trigger:'blur'}],
  re_pwd:[{required:true,message:'请再次输入密码',trigger:'blur'}]
})
</script>

<template>

  <el-form :model="form" label-width="auto" style="max-width: 600px" :rules="rules">
    <el-form-item label="您的旧密码" prop="old_pwd">
      <el-input  v-model="form.old_pwd" />
    </el-form-item>
    <el-form-item label="您的新密码" prop="new_pwd">
      <el-input v-model="form.new_pwd" />
    </el-form-item>
    <el-form-item label="请确认您的新密码" prop="re_pwd">
      <el-input v-model="form.re_pwd" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="updatepwd" v-loading.fullscreen.lock="fullscreenLoading">更新</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped>

</style>